//
//  ESCommentBar.m
//  Eyeshot
//
//  Created by admin on 15/7/8.
//  Copyright (c) 2015年 eyeshot. All rights reserved.
//

#define kCommentBarPadding 2*kVertical
#import "ESCommentBar.h"


@interface ESCommentBar ()
@end

@implementation ESCommentBar

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.width = SCREEN_WIDTH;
        self.height = 10 * kVertical;
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comment-bar-bg"]];
        imageView.width = SCREEN_WIDTH;
        imageView.height = self.height;
        
        UIButton *voiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [voiceBtn setBackgroundImage:[UIImage imageNamed:@"comment-bar-voice"] forState:UIControlStateNormal];
        [voiceBtn setBackgroundImage:[UIImage imageNamed:@"comment-bar-voice-click"] forState:UIControlStateHighlighted];
        
        UIButton *keyBoardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [keyBoardBtn setBackgroundImage:[UIImage imageNamed:@"comment-bar-keyboard"] forState:UIControlStateNormal];
        [keyBoardBtn setBackgroundImage:[UIImage imageNamed:@"comment-bar-keyboard-click"] forState:UIControlStateHighlighted];
        
        UIButton *atBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [atBtn setBackgroundImage:[UIImage imageNamed:@"comment_bar_at_icon"] forState:UIControlStateNormal];
        [atBtn setBackgroundImage:[UIImage imageNamed:@"comment_bar_at_icon_click"] forState:UIControlStateHighlighted];
        
        UITextField *middleField = [[UITextField alloc] init];
        middleField.borderStyle = UITextBorderStyleRoundedRect;
        middleField.placeholder = @"写评论...";
        
        UIButton *middleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [middleBtn setBackgroundImage:[UIImage imageNamed:@"comment-bar-record"] forState:UIControlStateNormal];
        [middleBtn setTitle:@"按住 说话" forState:UIControlStateNormal];
        [middleBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [middleBtn setBackgroundImage:[UIImage imageNamed:@"comment-bar-record-click"] forState:UIControlStateHighlighted];
        [middleBtn setTitle:@"松手 结束" forState:UIControlStateHighlighted];
        [middleBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateHighlighted];
        middleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        
        [self addSubview:imageView];
        [self addSubview:voiceBtn];
        [self addSubview:keyBoardBtn];
        [self addSubview:atBtn];
        [self addSubview:middleField];
        [self addSubview:middleBtn];
        
        //设置return键的类型
        middleField.returnKeyType = UIReturnKeySend;
//        self.backgroundColor = [UIColor blackColor];
//        voiceBtn.backgroundColor = [UIColor greenColor];
//        atBtn.backgroundColor = [UIColor greenColor];
//        middleField.backgroundColor = [UIColor yellowColor];
        _atBtn = atBtn;
        _voiceBtn = voiceBtn;
        _middleField = middleField;
        _keyBoardBtn = keyBoardBtn;
        _middleBtn = middleBtn;
        
        CGFloat width = self.width;
        CGFloat height = self.height;
        _voiceBtn.frame = CGRectMake(kCommentBarPadding, kCommentBarPadding, 6 * kVertical, 6 * kVertical);
        _keyBoardBtn.frame = CGRectMake(kCommentBarPadding, kCommentBarPadding, 6 * kVertical, 6 * kVertical);
        _middleField.frame = CGRectMake(2 * kCommentBarPadding + 6 * kVertical, kCommentBarPadding, width - 4 * kCommentBarPadding - 12 * kVertical, height - 2 * kCommentBarPadding);
        _middleBtn.frame = CGRectMake(2 * kCommentBarPadding + 6 * kVertical, kCommentBarPadding, width - 4 * kCommentBarPadding - 12 * kVertical, height - 2 * kCommentBarPadding);
        _atBtn.frame = CGRectMake(width - kCommentBarPadding - 6 * kVertical, kCommentBarPadding, 6 * kVertical, 6 * kVertical);
        
    }
    return self;
}

- (ESCommentMode) textMode {
    _voiceBtn.hidden = NO;
    _middleField.hidden = NO;
    _keyBoardBtn.hidden = YES;
    _middleBtn.hidden = YES;
    return ESCommentTextMode;
}

- (ESCommentMode) voiceMode {
    _keyBoardBtn.hidden = NO;
    _middleBtn.hidden = NO;
    _voiceBtn.hidden = YES;
    _middleField.hidden = YES;
    return ESCommentVoiceMode;
}

@end
